﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FTchina;
//从我的新闻审阅系统里移植的
public partial class UI_ChangePassWord : System.Web.UI.Page
{
    string id = string.Empty;
    string grid = string.Empty;//记者等修改用户名的id
    protected void Page_Load(object sender, EventArgs e)
    {
        basic.CheckAdmin(this);
        basic.ChkPoewr(this, FTchina.Api.htmlpath.GetCurrentPagePath());

        grid = FTchina.Library.MasterHelper.Luruid;
        id = grid;//如果是个人登陆则将id赋值为本人id，即不能修改别人并避免id获取错误
        if (!IsPostBack)
        {

            if (id.Length != 0) { GetData();   btnok.Text = "确定修改"; }


 
        }

 
    }



    
    private void GetData()
    {
        string GetDataSql = "select * from Master where link=" + id + "";
        basic.Log(GetDataSql);
        DataTable dt = shujuku.GetDataTable(GetDataSql);
         txbnicheng.Text = dt.Rows[0]["nicheng"].ToString().Trim();

    }
    protected void btnok_Click(object sender, EventArgs e)
    {
        if (btnok.Text == "确定修改") UpDateUser();
         txbnicheng.Text = "";
    }
    //修改用户
    protected void UpDateUser()
    {

        string nicheng = basic.FilterSQL(txbnicheng.Text);
        if (nicheng.Length == 0) { JS.Alert("请输入登录昵称"); return; }
        string UpDateSql = string.Empty;
        if (txbupsw.Text.Length == 0 & txbupsw2.Text.Length == 0)
        {
            UpDateSql = "update Master set nicheng='" + nicheng + "' where link=" + id;
        }
        else
        {
            if (txbupsw.Text != txbupsw2.Text) { JS.Alert("两次密码输入不一致！"); return; }
            if (txbupsw.Text.Length == 0) { JS.Alert("请输入密码"); return; }
            string userpsw = MD5MK.MD5String(basic.FilterSQL(txbupsw.Text));
            //不能更改用户名
            UpDateSql = "update Master set nicheng='" + nicheng + "',Master_Password='" + userpsw + "' where link=" + id;
        }
 
        UImsg.PageRender(shujuku.ExecuteSql(UpDateSql));


    }


}
